// components/ElecSealSmallPopup/ElecSealSmallPopup.js
import ElecSeal from '../../utils/ElecSealSmall.js'
let reqJs = require('../../utils/req.js')

const app = getApp();
Component({
    options: {
        addGlobalClass: true,
    },
    /**
     * 组件的属性列表
     */
    properties: {
        ElecSealSmallPopupShow: {
            type: Boolean,
            value: false,
            observer: function (newVal, oldVal) {
                // 页面被展示
                
                if (newVal) {
                    // console.log('>>>>>>>值变化了', newVal)
                    this.setData({
                        popupShow: newVal,
                    })
                }

            },
        },
        popupData: {
            type: Object,
            value: {},
            observer: function (newVal, oldVal) {
                
                // 页面被展示
                if (newVal) {
                    console.log('>>>>>>>值变化了', newVal)
                    this.setData({
                        popupData: newVal
                    })
                }

            },
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        popupData:{},//数据
        flag:false,
    },

    /**
     * 组件的方法列表
     */
    methods: {
        // 后门
        BackDoorBind() {
            this.verification()
        },
        // 核销
        verification() {

            let verification_code = this.data.popupData.verification_code

            reqJs.verification(verification_code).then(res => {
                console.log(res)

                let popupData = this.data.popupData

                popupData.is_use = 1
                this.setData({
                    popupData,
                    flag:true
                })


            })
        },
        // 盖章
        touchstart(e) {

            console.log(this.data.flag)
            // 是否已经被核销 
            if (this.data.flag) {

                return

            }
            // 测试
            // this.verification()

            // console.log(e)
            var that = this
            ElecSeal.touchStart(e, function (sealCode, SealCode) {
                    console.log(sealCode)
                    switch (sealCode) {
                        case '1234SEAL9':
                            that.verification()
                            break;
                        case '123SE6AL9':
                            that.verification()
                            break;
                        case '1S3EA6L89':
                            that.verification()
                            break;
                        case '1S34EAL89':
                            that.verification()
                            break;
                        case 'fail':
                            // that.setData({
                            //   showInputCode: true
                            // })
                            break;
                        case 'false':
                            // that.setData({
                            //   showInputCode: true
                            // })
                            break;
                        default:
                            // that.setData({
                            //   showInputCode: true,
                            // })
                    }
                },
              
            )

        },
        // 关闭弹窗
        closeModeAi() {



            this.triggerEvent('closeModeAi', {
                data: '关闭窗口'
            })
            this.setData({
                ElecSealSmallPopupShow: false
            })
        },
    }
})